package com.caipiao.crawler.shengfucang;

import com.alibaba.fastjson.JSON;
import com.caipiao.crawler.mapper.LotteryNumberMapper;
import com.caipiao.crawler.model.LotteryNumber;
import com.caipiao.util.DBTools;
import org.apache.ibatis.session.SqlSession;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by adminitrator on 2018/7/28.
 */
public class ShengfucangDetailPipeline implements Pipeline {

    @Override
    public synchronized void process(ResultItems resultItems, Task task) {
        LotteryNumber m = resultItems.get("model");
        System.err.println("pipe process:" + Thread.currentThread().getId());
        if(m == null) {
            return;
        }
        commit(m);
    }

    public void commit(LotteryNumber model) {
        System.err.println("commit");
        System.err.println(JSON.toJSONString(model));
        //TODO 更新奖池和销售金额，更新赛事关联赔率已经赛事结果
        SqlSession session = DBTools.getSession();
        LotteryNumberMapper mapper = session.getMapper(LotteryNumberMapper.class);
        mapper.updetaBymodelForSfcOrJqc(model);
        session.commit();
        session.close();

    }

}
